package com.onLineCar.manages.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onLineCar.manages.pojo.CarModel;
import com.onLineCar.manages.pojo.VehicleLevel;
import com.onLineCar.manages.mapper.VehicleLevelMapper;
import com.onLineCar.manages.pojo.request.CarLevelRequest;
import com.onLineCar.manages.service.VehicleLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 车辆级别表 服务实现类
 * </p>
 *
 * @author zhucaiyi
 * @since 2023-12-10
 */
@Service
public class VehicleLevelServiceImpl extends ServiceImpl<VehicleLevelMapper, VehicleLevel> implements VehicleLevelService {

    @Override
    public IPage<VehicleLevel> queryCarLevel(CarLevelRequest carLevelRequest) {
        LambdaQueryWrapper<VehicleLevel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(StringUtils.isNoneBlank(carLevelRequest.getLevelName()), VehicleLevel::getLevelName, carLevelRequest.getLevelName());
        lambdaQueryWrapper.like(StringUtils.isNoneBlank(carLevelRequest.getOperator()), VehicleLevel::getOperator, carLevelRequest.getOperator());
        return this.page(new Page<VehicleLevel>(Long.parseLong(carLevelRequest.getPageNum().toString()),
                        Long.parseLong(carLevelRequest.getPageSize().toString())),
                lambdaQueryWrapper);
    }

    @Override
    public Boolean addCarLevel(VehicleLevel vehicleLevel) {
        return this.save(vehicleLevel);
    }

    @Override
    public VehicleLevel queryCarLevelById(Long id) {
        return this.getById(id);
    }

    @Override
    public Boolean UpdateCarLevel(VehicleLevel vehicleLevel) {
        return this.updateById(vehicleLevel);
    }

    @Override
    public Boolean deleteCarLevelById(Long id) {
        return this.removeById(id);
    }
}
